package com.juneng.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.juneng.common.R;
import com.juneng.utils.Func;
import java.util.List;

import com.juneng.vo.BookTypeChildrenVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.juneng.entity.BookType;
import com.juneng.dto.BookTypeDto;
import com.juneng.dto.BookTypeQueryDto;
import com.juneng.vo.BookTypeVo;
import com.juneng.service.IBookTypeService;

/**
 *  控制器
 *
 * @author zds
 * @since 2021-07-14
 */
@RestController
@AllArgsConstructor
@RequestMapping("bookType")
@Api(tags = "相关接口")
public class BookTypeController {

	private IBookTypeService bookTypeService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperation(value = "详情", notes = "传入id")
	public R<BookType> detail(Integer id) {
		BookType detail = bookTypeService.getById(id);
		return R.success(detail);
	}

	/**
	 * 二级分页
	 */
	@GetMapping("/fatherPage")
	@ApiOperation(value = "二级分页", notes = "传入bookType")
	public R<IPage<BookTypeVo>> fatherPage(BookTypeQueryDto dto) {
		IPage<BookTypeVo> pages = bookTypeService.fatherPage(dto);
		return R.success(pages);
	}

	/**
	 * 三级分页
	 */
	@GetMapping("/sonPage")
	@ApiOperation(value = "二级分页", notes = "传入bookType")
	public R<IPage<BookTypeVo>> sonPage(BookTypeQueryDto dto) {
		IPage<BookTypeVo> pages = bookTypeService.sonPage(dto);
		return R.success(pages);
	}

	/**
	 * 列表
	 */
	@GetMapping("/sonList")
	@ApiOperation(value = "不分页", notes = "传入bookType")
	public R<List<BookType>> sonList(BookTypeQueryDto dto) {
		List<BookType> list = bookTypeService.sonList(dto);
		return R.success(list);
	}

	/**
	 * 列表 
	 */
	@GetMapping("/list")
	@ApiOperation(value = "不分页", notes = "传入bookType")
	public R<List<BookType>> list(BookTypeQueryDto dto) {
		List<BookType> list = bookTypeService.list(dto);
		return R.success(list);
	}

	/**
	 * 新增 
	 */
	@PostMapping("/save")
	@ApiOperation(value = "新增", notes = "传入bookType")
	public R save(@RequestBody BookTypeDto dto) {
		return R.success(bookTypeService.save(dto));
	}

	/**
	 * 新增 父类
	 */
	@PostMapping("/saveParent")
	@ApiOperation(value = "新增", notes = "传入bookType")
	public R saveParent(@RequestBody BookTypeDto dto) {
		return R.success(bookTypeService.saveParent(dto));
	}

	/**
	 * 修改 
	 */
	@PutMapping("/update")
	@ApiOperation(value = "修改", notes = "传入bookType")
	public R update(@RequestBody BookTypeDto dto) {
		return R.success(bookTypeService.updateById(dto));
	}

	/**
	 * 删除 
	 */
	@DeleteMapping("/remove")
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.success(bookTypeService.deleteLogic(Func.toIntList(ids)));
	}

	@GetMapping("/children")
	@ApiOperation(value = "所有元素")
	public R children() {
		List<BookTypeChildrenVo> children = bookTypeService.children();
		return R.success(children);
	}
}
